<extend file='../master'/>
<block name="content">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#tab1">文章列表</a></li>
        <li><a href="{{site_url('site/catLists')}}" role="tab">栏目列表</a></li>
    </ul>
    <br/>
    <form action="" method="post" class="form-horizontal" role="form">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">文章管理</h3>
            </div>

            <div class="panel-body">
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">栏目</label>
                    <div class="col-sm-10">
                        <select name="pid" class="form-control">
                            <option value="0">顶级栏目</option>
                            <foreach from="$cat" value="$c">
                                <option value="{{$c['cid']}}">{{$c['name']}}</option>
                            </foreach>

                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">标题</label>
                    <div class="col-sm-10">
                        <input type="text" name="title" class="form-control" id="" placeholder="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">作者</label>
                    <div class="col-sm-10">
                        <input type="text" name="author" class="form-control" id="" placeholder="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">点击数</label>
                    <div class="col-sm-10">
                        <input type="text" name="click" class="form-control" id="" placeholder="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">缩略图</label>
                    <div class="col-sm-10">
                        <div class="input-group">
                            <input type="text" class="form-control" name="thumb" readonly="" value="">
                            <div class="input-group-btn">
                                <button onclick="upImage(this)" class="btn btn-default" type="button">选择图片</button>
                            </div>
                        </div>
                        <div class="input-group" style="margin-top:5px;">
                            <img src="resource/images/nopic.jpg" class="img-responsive img-thumbnail" width="150">
                            <em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="removeImg(this)">×</em>
                        </div>
                    </div>

                    <script>
                        //上传图片
                        function upImage(obj) {
                            require(['util'], function (util) {
                                options = {
                                    multiple: false,//是否允许多图上传
                                    data: '',
                                    hash: 1
                                    //hash为确定上传文件标识（可以以用户编号，标识为此用户上传的文件，系统使用这个字段值来显示文件列表），data为数据表中的data字段值，开发者根据业务需要自行添加
                                };
                                util.image(function (images) {             //上传成功的图片，数组类型 
                                    $("[name='thumb']").val(images[0]);
                                    $(".img-thumbnail").attr('src', images[0]);
                                }, options)
                            });
                        }

                        //移除图片 
                        function removeImg(obj) {
                            $(obj).prev('img').attr('src', 'resource/images/nopic.jpg');
                            $(obj).parent().prev().find('input').val('');
                        }
                    </script>
                </div>
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">正文</label>
                    <div class="col-sm-10">
                        <textarea id="container" name="content" style="height:300px;width:100%;"></textarea>
                        <script>
                            util.ueditor('container', {hash: 2, data: 'hd'}, function (editor) {
                                //这是回调函数 editor是百度编辑器实例
                            });
                        </script>
                    </div>
                </div>
            </div>
        </div>
        <button class="btn btn-primary">保存</button>
        <a href="javascript:history.back();" type="button" class="btn btn-success">返回</a>
    </form>
</block>